package org.renhj.provider;


import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.string.StringEncoder;
import org.renhj.provider.handler.RpcProviderHandler;
import org.renhj.provider.server.RpcServer;
import org.renhj.register.Register;
import org.renhj.register.ZookeeperRegister;
import org.renhj.rpc.RpcDecoder;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.net.Inet4Address;
import java.util.Arrays;

@SpringBootApplication
public class RpcServerApplication implements CommandLineRunner, DisposableBean {

    RpcServer rpcServer;

    public static void main(String[] args) throws Exception {
        SpringApplication.run(RpcServerApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        // 从args中获取启动端口
        int port = Integer.parseInt(args[0]);

        // 1、启动netty rpc 服务端
        rpcServer = new RpcServer(port);
        rpcServer.startServer();
    }

    @Override
    public void destroy() throws Exception {
        rpcServer.stopServer();
    }
}
